import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GoodsQuery, GoodsVO, GoodsForm } from '@/api/operates/goods/types';

/**
 * 商品列表
 * @param query 
 * @returns 
 */
export const listGoods = (query: GoodsQuery): AxiosPromise<TableInfoVO<GoodsVO>> => {
  return request({
    url: '/goods/list',
    method: 'get',
    params: query
  });
};

/**
 * 商品详情
 * @param id 
 * @returns 
 */
export const getGoods = (id: string | number): AxiosPromise<GoodsForm> => {
  return request({
    url: `/goods/${id}`,
    method: 'get'
  });
};

/**
 * 商品添加
 * @param data 
 * @returns 
 */
export const addGoods = (data: GoodsForm) => {
  return request({
    url: '/goods',
    method: 'post',
    data: data
  });
};

/**
 * 商品修改
 * @param data 
 * @returns 
 */
export const updateGoods = (data: GoodsForm) => {
  return request({
    url: '/goods',
    method: 'put',
    data: data
  });
};

/**
 * 商品上架下架-审核
 * @param id 
 * @returns 
 */
export const enableGoods = (id: string | number) => {
  return request({
    url: `/goods/enable/${id}`,
    method: 'put'
  });
};

/**
 * 商品删除
 * @param id 
 * @returns 
 */
export const delGoods = (id: string | number) => {
  return request({
    url: `goods/${id}`,
    method: 'delete'
  });
};